package tool.zyk.nio;

import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Scanner;

/**
 * author: zyk
 * datetime: 2024/1/27 09:44
 * describe:
 */
@Slf4j
public class NioClient {
    public static void main(String[] args) {
        try (Socket socket = new Socket("127.0.0.1", 8087)) {
            log.info("socket init success:{} ", socket);
            OutputStream outputStream = socket.getOutputStream();

            Scanner scanner = new Scanner(System.in);
            while (true) {
                System.out.println("请输入：");
                String s = scanner.nextLine();
                outputStream.write(s.getBytes());
                outputStream.flush();
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
